package flexo.examples;

import flexo.graphic.Camera;
import flexo.math.Vector;
import flexo.scene.Node;
import flexo.scene.Scene;

import flexo.input.EventType;
import flexo.input.entity.*;

public abstract class Test_Graphic_Base extends Test_Base
{
	Scene mainScene;
	Node camPosNode;
	Node camTargetNode;
	
	Entity fpsMov;
	Entity fpsLook;
	
	public void init()
	{			
		super.init();
		mainScene = scene.addScene("mainScene");
		camPosNode = mainScene.addChild("camPosNode");
		camTargetNode = camPosNode.addChild("camTargetNode");
		
		Camera cam = graphic.addCamera3D("mainScene");
		cam.setPositionNode(camPosNode);
		cam.setTargetNode(camTargetNode);
		
		flexo.input.entity.Entity exit = input.addExitOnEsc();
		exit.attachTo(mainScene);
		
		file.addPath("media");
		
		camPosNode.setPosition(new Vector(0,0,4));
		camTargetNode.setPosition(new Vector(0,0,-flexo.input.entity.FPSLook.RADIUS));
		
		addInput();
	}
	
	protected void addInput()
	{
		// Register WASD
		input.addAction(FPSMovement.MOVE_FORWARD,
				flexo.input.EventType.KEY_W,true);
		input.addAction(FPSMovement.MOVE_BACKWARD,
				EventType.KEY_S,true);
		input.addAction(FPSMovement.STRAFE_LEFT,
				EventType.KEY_A,true);
		input.addAction(FPSMovement.STRAFE_RIGHT,
				EventType.KEY_D,true);
		
		fpsMov = input.addFPSMovement(camTargetNode);
		fpsMov.attachTo(camPosNode);

		// Register mouse controls
		input.addAction(FPSLook.LOOK_UP,
				EventType.MOUSE_Y_POS);
		input.addAction(FPSLook.LOOK_DOWN,
				EventType.MOUSE_Y_NEG);
		input.addAction(FPSLook.LOOK_LEFT,
				EventType.MOUSE_X_NEG);
		input.addAction(FPSLook.LOOK_RIGHT,
				EventType.MOUSE_X_POS);
		
		fpsLook = input.addFPSLook();
		fpsLook.attachTo(camTargetNode);
	}
}
